import router from './router'
import { getToken } from './utils/auth'
// 前置守卫
const whiteList = ['/login', '/404']
router.beforeEach(async(to, from, next) => {
  const token = getToken()
  if (token) {
    next()
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
// 后置守卫
router.afterEach((to, from) => {
  if (to.meta?.title) {
    document.title = to.meta.title
  }
})
